import callApp from './jsbridge'

// 小于某个版本
export function isVersionBefore (versionRefer) {
  var version = callApp.appInfo.version
  var versionArr = version.split('.')
  var versionReferArr = versionRefer.split('.')
  var result = false
  for (var i = 0; i < versionReferArr.length; i++) {
    var diff = versionArr[i] - versionReferArr[i]
    if (diff > 0) {
      result = false
      break
    } else if (diff < 0) {
      result = true
      break
    }
  }
  return result
}

// 获取url参数
export function getUrlParams (key) {
  const reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)', 'i')
  const _arr = window.location.href.split('?')
  const search = decodeURIComponent(_arr[1] ? _arr[1] : '')
  const r = search.match(reg)
  if (r !== null) return unescape(r[2])
  return ''
}
